package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.dto.*;
import com.ruoyi.common.core.domain.entity.AiConfig;
import com.ruoyi.common.core.domain.entity.RaBase;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IArmFrontTermService;
import com.ruoyi.system.service.IFrontTermService;
import com.ruoyi.system.service.IRaBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @DATE : 2024/05/22 13:22
 */
@RestController
@RequestMapping("/system/real")
public class RaBaseController {

    @Autowired
    private IRaBaseService server;

    @Autowired
    private IFrontTermService frontTermService;

    @Autowired
    private IArmFrontTermService armFrontTermService;

    /**
     * 获取江北水厂实时数据
     */
    @PreAuthorize("@ss.hasPermi('system:real:list')")
    @GetMapping("/list")
    public AjaxResult list()
    {
        RaBase raBase = server.selectRaBaseByOne();
        return AjaxResult.success(raBase);
    }

    /**
     * 数据趋势页面数据
     * @param changeDto changeDto
     * @return AjaxResult
     */
    @PostMapping("/listChange")
    public AjaxResult listChange(@RequestBody ChangeDto changeDto)
    {
        return server.listChange(changeDto);
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, ChangeDto changeDto)
    {
        List<ChangeResultDto> changeResultDtos = server.listChangeExport(changeDto);
        ExcelUtil<ChangeResultDto> util = new ExcelUtil<ChangeResultDto>(ChangeResultDto.class);
        util.exportExcel(response, changeResultDtos, "数据视图");
    }

    @GetMapping("/selectFrontTerm")
    public AjaxResult selectFrontTerm() {
        return frontTermService.selectFrontTerm();
    }

    @GetMapping("/selectArmFrontTerm")
    public AjaxResult selectArmFrontTerm() {
        return armFrontTermService.selectArmFrontTerm();
    }

    @PutMapping("/updateFrontTerm")
    public AjaxResult updateFrontTerm(@RequestBody FrontTermDto frontTermDto) {
        return frontTermService.updateFrontTerm(frontTermDto);
    }

    @PutMapping("/updateArmFrontTerm")
    public AjaxResult updateArmFrontTerm(@RequestBody ArmFrontTermDto armFrontTermDto) {
        return armFrontTermService.updateArmFrontTerm(armFrontTermDto);
    }

    /**
     * 历史数据查询页面接口
     * @param queryDto
     * @return
     */
    @PostMapping("/queryModel")
    public AjaxResult queryModel(@RequestBody QueryDto queryDto) {
        return AjaxResult.success("成功获取模糊查询结果！", server.queryModel(queryDto));
    }

    /**
     * 将history数据导入到ra-vue
     * @param startDate
     * @param endDate
     * @selectAiConfig
     */
    @PostMapping("/getRealModelByDate")
    public AjaxResult getRealModelByDate(String startDate, String endDate) {
        return server.getRealModelByDate(startDate, endDate);
    }

    @GetMapping("/selectAiConfig")
    public AjaxResult selectAiConfig() {
        return AjaxResult.success(server.selectAiConfig());
    }

    @PutMapping("/updateAiConfig")
    public AjaxResult updateAiConfig(@RequestBody AiConfig aiConfig) {
        return server.updateAiConfig(aiConfig);
    }

    @GetMapping("/selectRead")
    public AjaxResult selectRead() {
        return server.selectRead();
    }

    @DeleteMapping(value = {"/","/{id}"})
    public AjaxResult delRaBase(@PathVariable(value = "id", required = false) Long id)
    {
        return server.delRaBase(id);
    }

}
